package com.lmc.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;

import com.lmc.R;
import com.lmc.recreation.RecreationListActivity;
import com.qxzn.app.bean.Recreation;

import java.net.URLDecoder;
import java.util.List;

public class RecreationGridListAdapter extends BaseAdapter {
    Context context;
    List<Recreation.DataBean> list;

    public RecreationGridListAdapter(Context context, List<Recreation.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Recreation.DataBean getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.recreation_grid_item, null);
            holder = new ViewHolder();
            holder.grid_view = convertView.findViewById(R.id.grid_view);
            holder.tv_title = convertView.findViewById(R.id.tv_title);
            holder.tv_more = convertView.findViewById(R.id.tv_more);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final Recreation.DataBean bean = getItem(position);
        holder.tv_title.setText(bean.getName());
        holder.grid_view.setAdapter(new RecreationGridAdapter(context, bean.getItems()));

        holder.tv_more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //更多
                Intent intent = new Intent(context, RecreationListActivity.class);
//                intent.putExtra("bean",bean);
                intent.putExtra("name", bean.getName());
                intent.putExtra("id",bean.getId() + "");
                context.startActivity(intent);
            }
        });
        return convertView;
    }

    private class ViewHolder {
        GridView grid_view;
        TextView tv_title;
        TextView tv_more;
    }
}
